<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>动态桥梁挠度曲线</title>
    <script src="{{ url_for('static', filename='plotly-latest.min.js') }}"></script>
</head>
<body>
    <h1>动态桥梁挠度曲线</h1>
    <div id="plot" style="width: 800px; height: 400px;"></div>
    <script>
        const plotDiv = document.getElementById('plot');
        let layout = {
            title: "桥梁挠度曲线",
            xaxis: { title: "位置 (m)" },
            yaxis: { title: "挠度 (m)" },
            legend: { x: 0, y: 1 }
        };

        // 初始加载数据
        fetchData();

        // 每20秒刷新一次
        setInterval(fetchData, 20000);

        function fetchData() {
            fetch('/get_data')
                .then(response => response.json())
                .then(data => {
                    const x = data.x;
                    const deflections_point = data.deflections_point;
                    const deflections_dist = data.deflections_dist;

                    // 更新图表数据
                    Plotly.newPlot(plotDiv, [
                        { x: x, y: deflections_point, name: '集中荷载', type: 'scatter' },
                        { x: x, y: deflections_dist, name: '均布荷载', type: 'scatter' }
                    ], layout);
                })
                .catch(error => console.error('Error fetching data:', error));
        }
    </script>
</body>
</html>